;(function(){
    $("#top-mycart").click(function(){
        location.href = "cart.html";
    });
    $(".search-btn").click(function(){
        location.href = `list.html?searchW=${encodeURI($("#nav-search").val())}`;
    })
    class Logininit{
        constructor(){
            this.init();
            this.loginEvent();
        }
        init(){
            let userObj = sessionStorage.getItem("token") ? JSON.parse(sessionStorage.getItem("token")) : {};
            if(userObj.isLogin === "ok"){
                this.isLogin =true;
            }
        }
        loginEvent(){
            let userObj = sessionStorage.getItem("token") ? JSON.parse(sessionStorage.getItem("token")) : {};
            if(this.isLogin){
                $(".index-reg").hide();
                $(".yet-login")[0].firstElementChild.innerHTML = "Hi,"+userObj.tel;
                $(".yet-login").show();

                $(".aside-no-login").hide();
                $(".aside-login").show();
                //退出登陆
                $(".logout").click(function(){
                    sessionStorage.removeItem("token");
                    location.reload();
                })
                //购物车个数显示
                let shopData = localStorage.getItem("shopData") ? JSON.parse(localStorage.getItem("shopData")) : [];
                if(shopData.length<1){
                    $(".nav-cart").children("i").hide();
                }else{
                    $(".nav-cart").children("i").show().html(shopData.length);
                }

            }else{
                $(".yet-login").hide();
                $(".index-reg").show();
                $(".aside-login").hide();
                $(".aside-no-login").show();
            }
        }
    }
    new Logininit();
})();